package com.emeraldparser.util;

import java.util.Map;

public abstract class AbstractMapEntry<K, V> implements Map.Entry<K, V> {

	@Override
	public int hashCode() {
		return (getKey()==null   ? 0 : getKey().hashCode()) ^
	           (getValue()==null ? 0 : getValue().hashCode());
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (!(obj instanceof Map.Entry<?, ?>)) {
			return false;
		}
		
		Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
		
		return (getKey()==null ? other.getKey()==null : getKey().equals(other.getKey()))
		    && (getValue()==null ? other.getValue()==null : getValue().equals(other.getValue()));
	}

	@Override
	public String toString() {
		return getKey() + "=" + getValue();
	}

}
